/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.dusa.worklog.viewer;

import cz.dusa.worklog.controller.WorklogDataManager;
import cz.dusa.worklog.datalib.Customer;
import java.util.List;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Node;

/**
 *
 * @author vdusa
 */
public class CustomerChildFactory extends ChildFactory<Customer> {
    private final List<Customer> customerList;
    private WorklogDataManager worklogDataManager;

    CustomerChildFactory(List<Customer> resultList, WorklogDataManager worklogDataManager) {
        this.customerList = resultList;
        this.worklogDataManager = worklogDataManager;
    }

    @Override
    protected boolean createKeys(List<Customer> list) {
        for (Customer c : customerList) {
            list.add(c);
        }
        return true;
    }

    @Override
    protected Node createNodeForKey(Customer c) {
        CustomerNode node = new CustomerNode(c);
        return node;
    }

    void removeCustomer(Customer customer) {
        customerList.remove(customer);
        refresh(true);
    }

    void addCustomer(Customer customer){
        customerList.add(customer);
        refresh(true);
    }

    void updateCustomer(Customer customer){        
        int index = customerList.indexOf(customer);
        if (index >= 0){
            customerList.set(index, customer);
            refresh(true);
        }
    }
}